<%--
    Document   : LibraryBook
    Created on : 14.02.2010, 12:34:31
    Author     : Morfant
--%>

<%@page import="java.util.Map"%>
<%@page import="stud.cp.user.valueobjects.Parameter"%>
<%@page import="stud.cp.user.valueobjects.Property"%>
<%@page import="java.util.List"%>
<%@page import="stud.cp.user.valueobjects.DBObject"%>
<%@page import="stud.cp.user.valueobjects.DBObjectType"%>
<%@page import="stud.cp.user.valueobjects.PropertyGroup"%>
<%@page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" language="java"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <%@include file="/header.jsp" %>
    <body>
        <div class="page">
            <%@include file="/cap.jsp" %>
            <div id="main">
                <%DBObject object = (DBObject) request.getAttribute(PluginConst.WEAPON);
                            if (object != null) {%>
                <h2>Просмотр оружия.  <%=object.getName()%>.</h2>
                <table id="buttontable">
                    <tr>
                        <th>
                            <div id="objectmenucontainer">
                                <ul id="objectmenu">
                                    <li><a href="<%= response.encodeURL("object-action.do")
                                                            + "?"
                                                            + PluginConst.SUBACTION
                                                            + "="
                                                            + PluginConst.GET_EDIT_PAGE
                                                            + "&"
                                                            + PluginConst.OBJECT_ID
                                                            + "="
                                                            + object.getObject_id()%>">Редактировать</a></li>
                                </ul>
                            </div>
                        </th>
                                                <th>
                            <div id="objectmenucontainer">
                                <ul id="objectmenu">
                                    <li><a href="<%= response.encodeURL("object-action.do")
                                                            + "?"
                                                            + PluginConst.SUBACTION
                                                            + "="
                                                            + PluginConst.GET_HISTORY_PAGE
                                                            + "&"
                                                            + PluginConst.OBJECT_ID
                                                            + "="
                                                            + object.getObject_id()%>">История</a></li>
                                </ul>
                            </div>
                        </th>
                        <th>
                            <div id="objectmenucontainer">
                                <ul id="objectmenu">
                                    <li><a href="<%= response.encodeURL("object-action.do")
                                                            + "?"
                                                            + PluginConst.SUBACTION
                                                            + "="
                                                            + PluginConst.GET_DELETE_PAGE
                                                            + "&"
                                                            + PluginConst.OBJECT_ID
                                                            + "="
                                                            + object.getObject_id()%>">Удалить</a></li>
                                </ul>
                            </div>
                        </th>
                    </tr>
                </table>
                <fieldset>
                    <legend>Данные</legend>
                    <p>
                        <span class="highlight-delete-item">
                            <label for="<%=PluginConst.WEAPON_NAME%>">
                                Название оружия:
                            </label>
                        </span>
                        <%=object.getName()%>
                    <p/>
                    <p>
                        <span class="highlight-delete-item">
                            <label for="<%=PluginConst.WEAPON_DESCRIPTION%>">
                                Описание оружия:
                            </label>
                        </span>
                        <textarea readonly
                                  rows="5"
                                  cols="50"
                                  name="show"
                                  ><%=object.getDescription()%></textarea>
                    <p/>

                    <%List<Parameter> list = (List<Parameter>) request.getAttribute(PluginConst.PROPERTY_VALUES_LIST);
                                                    if ((list != null) && (list.size() > 0)) {
                                                        String lastGroupName = "";
                                                        String propertyType = "";
                                                        Map<Integer, DBObject> referenceObjectMap =
                                                                (Map<Integer, DBObject>) request.getAttribute(PluginConst.REFERENCE_WEAPON_RESORSES);
                                                        for (Parameter item : list) {
                                                            propertyType = item.getProperty_type_id().toString();
                                                            if (!item.getProperty_group_name().equals(lastGroupName)) {
                                                                if (!lastGroupName.equals("")) {%>
                </fieldset>
                <%}%>
                <fieldset>
                    <legend><%=item.getProperty_group_name()%></legend>
                    <%lastGroupName = item.getProperty_group_name();
                                                                                }%>
                    <p>
                        <span class="highlight-delete-item">
                            <label for="<%=item.getProperty_value_id()%>"><%=item.getProperty_name()%>:</label>
                        </span>
                        <% %>
                        <% if (propertyType.equals(PluginConst.TEXT_TYPE)) {%>
                        <%=(item.getValue() != null) ? item.getValue() : "Значение не заданно"%>
                        <%}%>
                        <% if (propertyType.equals(PluginConst.REFERENCE_TYPE)) {%>
                        <%DBObject referenceObject = referenceObjectMap.get(item.getProperty_id());
                             if (referenceObject != null) {
                        %>
                        <a href="<%= response.encodeURL("object-action.do")
                                                + "?"
                                                + PluginConst.SUBACTION
                                                + "="
                                                + PluginConst.GET_VIEW_PAGE
                                                + "&"
                                                + PluginConst.OBJECT_ID
                                                + "="
                                                + referenceObject.getObject_id()%>"
                                                target="_blank"><%=referenceObject.getName()%></a>
                        <%} else {%>
                        -
                        <%}%>
                        <%}%>
                        <% if (propertyType.equals(PluginConst.LIST_TYPE)) {%>
                        <%=(item.getProperty_list_value() != null) ? item.getProperty_list_value() : "Значение не заданно"%>
                        <%}%>
                    <p/>
                    <%}%>
                </fieldset>
                <%}%>

                </fieldset>
                <%}%>
                <div id="objectmenucontainer">
                    <ul id="objectmenu">
                        <li><a href="<%= response.encodeURL("object-action.do")
                                                + "?"
                                                + PluginConst.SUBACTION
                                                + "="
                                                + PluginConst.GET_LIST
                                                + "&"
                                                + PluginConst.OBJECT_TYPE_ID
                                                + "="
                                                + object.getObject_type_id()%>">Вернуться к списку оружия</a></li>
                    </ul>
                </div>
            </div>
        </div>
    </body>
</html>
